package text5;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

class Jfarme extends JFrame{
    String flag = "你好";
    public Jfarme() throws HeadlessException {
        farme();
        Button();
        Hellobay();
        this.setVisible(true);
    }
    public void farme(){
        this.setTitle("点击");
        this.setSize(500,550);
        this.setDefaultCloseOperation(3);//关闭方法
        this.setAlwaysOnTop(true);//最上方
        this.setLocationRelativeTo(null);//居中
        this.setLayout(null);//默认容器
    }
    public void Button(){
        JButton button = new JButton("点击");
        button.setBounds(180,150,100,50);
        this.getContentPane().add(button);
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (flag.equals("你好")){
                    flag = "再见";
                    Hellobay();
                }
                else
                    flag = "你好";
                Hellobay();
            }
        });
    }
    public void Hellobay(){
        this.getContentPane().removeAll();
        JLabel jl = new JLabel(flag);
        Button();
        jl.setFont(new Font("宋体", 1, 20));
        jl.setBounds(20, 20, 150, 50);
        this.getContentPane().add(jl);
        this.getContentPane().repaint();
    }
}
public class Num1 {
    public static void main(String[] args) {
        Jfarme jf = new Jfarme();
    }
}
